﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Net.Mail;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace CIS.Web.Controllers
{
	[RoutePrefix("MeetingBooking")]
	public class MeetingBookingController : BaseDbController
	{
		public async Task<ActionResult> Index(string conferenceId)
		{
			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId && x.Status == ConstValues.Status.正常);

			if (conferenceMaster == null)
			{
				return RedirectToAction(nameof(HomeController.MainIndex), nameof(HomeController).GetControllerName());
			}

			var model = new BookingHotelModel();
			model.ConferenceId = conferenceId;
			model.CheckHint = string.IsNullOrEmpty(conferenceMaster.CheckHint) ? string.Empty :
					conferenceMaster.CheckHint.Replace("\r\n", ConstValues.strHtmlNewline);
			if (conferenceMaster.BenefitStartDate <= DateTime.Now && DateTime.Now <= conferenceMaster.BenefitEndDate)
			{
				model.IsBenefit = true;
			}
			else
			{
				model.IsBenefit = false;
			}

			model.HasHotel = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ConferenceId == conferenceId) == null ? false : true;
			model.HasTraffic = DbContext.TrafficMaster.AsNoTracking().FirstOrDefault(y => y.ConferenceId == conferenceId) == null ? false : true;

			var sysUserMaster = DbContext.SysUserMaster.AsNoTracking().FirstOrDefault(x => x.ID == LoginUser.UserID);
			model.FullName = sysUserMaster == null ? string.Empty : sysUserMaster.FullName;
			model.Mail = sysUserMaster == null ? string.Empty : sysUserMaster.Mail;
			model.Mobile = sysUserMaster == null ? string.Empty : sysUserMaster.Mobile;

			//获取币种的数量，，如果只有一个币种就不用弹出币种选择框
			var sql = DbContext.TrafficMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId &&
						x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key)

					.Union(DbContext.HotelMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.Join(DbContext.RoomMaster.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常),
							hotel => hotel.ID,
							room => room.HotelId,
							(hotel, room) => new
							{
								Currency = room.Currency
							}
						)
						.GroupBy(x => x.Currency).Select(x => x.Key));

			var sqlResult = await sql.ToListAsync();
			if (sqlResult.Count() == 1)
			{
				model.CurrencyCount = 1;
				model.Currency = sqlResult[0];
			}
			else
			{
				model.CurrencyCount = sqlResult.Count();
				model.Currency = string.Empty;
			}

			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			ViewBag.ConferenceId = conferenceId;
			ViewBag.ConferenceName = conferenceMaster.ConferenceName;

			return View(model);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> Submit(BookingHotelModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var errorHotelName = string.Empty;
			var errorRoomTypeName = string.Empty;
			var errorDate = string.Empty;
			var errorText = string.Empty;
			var isTrue = true;
			var orderNum = Utility.GetOrderNum(model.ConferenceId, ConstValues.OrderType.酒店);
			List<int> dummyList = new List<int>();
			List<Hotel> mailList = new List<Hotel>();

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == model.ConferenceId);

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				model.TotalList.ForEach(x =>
				{
					var hotelMaster = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.HotelId);
					var roomMaster = DbContext.RoomMaster.AsNoTracking().FirstOrDefault(y => y.RoomType == x.RoomTypeId && y.HotelId == x.HotelId);

					if (roomMaster != null)
					{
						dummyList = Utility.GetDummyRoomNum(model.ConferenceId, x.nameList.Count(), dummyList);
						int differenceInDays = (Convert.ToDateTime(x.CheckoutDate) - Convert.ToDateTime(x.CheckinDate)).Days;
						int dummyIndex = 0;
						var guestName = string.Empty;

						//由多组两个名字组成的list
						x.nameList.ForEach(z =>
						{
							#region ProfileHotelInfo
							var profileHotelInfo = new ProfileHotelInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfileHotelInfo),
								ConferenceId = x.ConferenceId,
								HotelId = x.HotelId,
								RoomType = roomMaster.RoomType,
								RoomId = string.Empty,
								IsCombine = x.NeedCombine == "true" ? true : false,
								Name1 = string.IsNullOrEmpty(z[0]) ? string.Empty : z[0].Trim(),
								Name2 = string.IsNullOrEmpty(z[1]) ? string.Empty : z[1].Trim(),
								CheckinDate = Convert.ToDateTime(x.CheckinDate),
								CheckoutDate = Convert.ToDateTime(x.CheckoutDate),
								OrderNum = orderNum,
								DummyRoomNum = dummyList[dummyIndex],
								Contact = x.ContactName.Trim(),
								ContactPhone = x.ContactMobile.Trim(),
								ContactMail = x.ContactMail.Trim(),
								Remark = string.IsNullOrEmpty(x.Remark) ? string.Empty : x.Remark.Trim(),
								Currency = x.Currency,
								Fee = roomMaster.Price1.Value * differenceInDays,
								Discount = roomMaster.Price2.Value * differenceInDays,
								Creator = LoginUser.UserName,
								CreateDate = DateTime.Now,
								CreateIP = LoginUser.IP,
								UserName = LoginUser.UserName,
								Status = ConstValues.Status.已预订
							};
							DbContext.ProfileHotelInfo.Add(profileHotelInfo);
							#endregion

							dummyIndex++;
							DateTime startDate = Convert.ToDateTime(x.CheckinDate);
							DateTime endDate = Convert.ToDateTime(x.CheckoutDate);
							while (isTrue && startDate < endDate)
							{
								#region RoomMaster
								var room = DbContext.RoomMaster.FirstOrDefault(y => y.HotelId == x.HotelId && y.RoomType == roomMaster.RoomType &&
											y.BookDate == startDate && y.Currency == x.Currency);
								if (room == null || room.LeftRoomCount.Value < 1)
								{
									isTrue = false;
									errorHotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.HotelId)?.HotelName;
									errorRoomTypeName = roomMaster.RoomType;
									errorDate = startDate.ToString("yyyy-MM-dd");
									errorText = Resources.MsgNotEnoughBookingRoom;
									break;
								}
								
								//如果填了两个名字
								if (!string.IsNullOrEmpty(z[0]) && !string.IsNullOrEmpty(z[1]))
								{
									if (room.LeftBedCount < room.RoomBedCount)
									{
										isTrue = false;
										errorHotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.HotelId)?.HotelName;
										errorRoomTypeName = roomMaster.RoomType;
										errorDate = startDate.ToString("yyyy-MM-dd");
										errorText = Resources.MsgNotEnoughBookingBed;
										break;
									}
									room.LeftRoomCount = room.LeftRoomCount.Value - 1;
									room.LeftBedCount = room.LeftBedCount.Value - room.RoomBedCount.Value;
								}
								else
								//只填了一个名字
								{
									//需要拼房
									if (x.NeedCombine == "true")
									{
										//剩余床位数至少要大于1
										if (room.LeftBedCount < 1)
										{
											isTrue = false;
											errorHotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.HotelId)?.HotelName;
											errorRoomTypeName = roomMaster.RoomType;
											errorDate = startDate.ToString("yyyy-MM-dd");
											errorText = Resources.MsgNotEnoughBookingBed;
											break;
										}
										//床位数为1,即大床房
										if (room.RoomBedCount % 2 != 0)
										{
											room.LeftRoomCount = room.LeftRoomCount.Value - 1;
											room.LeftBedCount = room.LeftBedCount.Value - 1;
										}
										else
										{
											//剩余床位数为偶数
											if (room.LeftBedCount.Value % 2 == 0)
											{
												room.LeftBedCount = room.LeftBedCount.Value - 1;
											}
											else
											{
												room.LeftRoomCount = room.LeftRoomCount.Value - 1;
												room.LeftBedCount = room.LeftBedCount.Value - 1;
											}
										}
									}
									else
									{
										//不拼房的话，剩余床位数至少要大于2
										if (room.LeftBedCount < room.RoomBedCount)
										{
											isTrue = false;
											errorHotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.HotelId)?.HotelName;
											errorRoomTypeName = roomMaster.RoomType;
											errorDate = startDate.ToString("yyyy-MM-dd");
											errorText = Resources.MsgNotEnoughBookingBed;
											break;
										}
										room.LeftRoomCount = room.LeftRoomCount.Value - 1;
										room.LeftBedCount = room.LeftBedCount.Value - room.RoomBedCount.Value;
									}
								}
								room.Updater = LoginUser.UserName;
								room.UpdateDate = DateTime.Now;
								room.UpdateIP = LoginUser.IP;
								#endregion

								#region CheckInInfo
								var checkinInfo = new CheckinInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.CheckinInfo),
									ConferenceId = x.ConferenceId,
									AttendenceId = profileHotelInfo.ID,
									HotelId = x.HotelId,
									RoomTypeId = room.ID,
									CheckinDate = startDate,
									Creator = LoginUser.UserName,
									CreateDate = DateTime.Now,
									CreateIP = LoginUser.IP,
									UserName = LoginUser.UserName,
								};
								DbContext.CheckinInfo.Add(checkinInfo);
								#endregion

								startDate = startDate.AddDays(1);
							}

							if (!string.IsNullOrEmpty(profileHotelInfo.Name1))
							{
								if (!string.IsNullOrEmpty(guestName))
								{
									guestName += conferenceMaster.IsInternational ? ConstValues.strComma : ConstValues.strCommaCn;
								}
								guestName += profileHotelInfo.Name1;
							}

							if (!string.IsNullOrEmpty(profileHotelInfo.Name2))
							{
								if (!string.IsNullOrEmpty(guestName))
								{
									guestName += conferenceMaster.IsInternational ? ConstValues.strComma : ConstValues.strCommaCn;
								}
								guestName += profileHotelInfo.Name2;
							}
						});

						var mailHotel = new Hotel()
						{
							HotelName = hotelMaster.HotelName,
							RoomType = roomMaster.RoomType,
							Price = x.Price,
							RoomNumber = x.RoomNumber,
							GuestName = guestName,
							CheckinDate = x.CheckinDate,
							CheckoutDate = x.CheckoutDate,
							//CheckinDate = conferenceMaster.IsInternational ? Convert.ToDateTime(x.CheckinDate).ToString("MM/dd/yyyy") : Convert.ToDateTime(x.CheckinDate).ToString("yyyy-MM-dd"),
							//CheckoutDate = conferenceMaster.IsInternational ? Convert.ToDateTime(x.CheckoutDate).ToString("MM/dd/yyyy") : Convert.ToDateTime(x.CheckoutDate).ToString("yyyy-MM-dd"),
							CheckinDaysCount = differenceInDays.ToString(),
						};
						mailList.Add(mailHotel);
					}
				});

				if (isTrue)
				{
					await DbContext.SaveChangesAsync();

					#region SendMail
					var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
								x.MailType == ConstValues.MailType.酒店交通服务邮箱 &&
								x.ConferenceId == model.ConferenceId);

					if (conferenceMailServerMaster == null)
					{
						conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
									x.MailType == ConstValues.MailType.会议邮箱 &&
									x.ConferenceId == model.ConferenceId);
					}

					if (conferenceMailServerMaster != null)
					{
						MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
						MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
						MailAddress to = new MailAddress(model.TotalList.FirstOrDefault().ContactMail);

						MailMessage message = Utility.GetMailContent(new MailModel
						{
							MailRemark = ConstValues.MailSubject.酒店预订,
							Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn,
							ConferenceId = conferenceMaster.ID,
							ConferenceName = conferenceMaster.ConferenceName,
							ConferenceNickName = conferenceMaster.ConferenceNickName,
							Contact = model.TotalList.FirstOrDefault().ContactName,
							TotalFee = model.TotalList.FirstOrDefault().TotalFee,
							HotelList = mailList
						});
						message.To.Add(to);

						if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
						{
							foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
							{
								if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
								{
									message.Bcc.Add(new MailAddress(cc.Trim()));
								}
							}
						}

						var mailTask = Task.Run(() =>
						{
							sender.SendMail(from, message, conferenceMailServerMaster.Password);
						});
					}
					#endregion

					transaction.Commit();
				}
			}

			if (isTrue)
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(errorText, errorDate, errorRoomTypeName)),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> BookTrafficSubmit(BookingHotelModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var orderNum = Utility.GetOrderNum(model.ConferenceId, ConstValues.OrderType.交通);
			List<Traffic> mailList = new List<Traffic>();

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == model.ConferenceId);

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				model.TrafficList.ForEach(x =>
				{
					var trafficMaster = DbContext.TrafficMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.TrafficId);
					if (trafficMaster != null)
					{
						var profileTrafficInfo = new ProfileTrafficInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfileTrafficInfo),
							ConferenceId = model.ConferenceId,
							TrafficId = x.TrafficId,
							FlightDate = Convert.ToDateTime(x.FlightDate),
							FlightNum = x.FlightNum,
							TrafficType = x.TrafficType,
							Remark = string.IsNullOrEmpty(x.Remark) ? string.Empty : x.Remark.Trim(),
							Currency = x.Currency,
							Fee = trafficMaster.Price.Value,
							FullName = string.IsNullOrEmpty(x.ContactName) ? string.Empty : x.ContactName.Trim(),
							Mail = string.IsNullOrEmpty(x.ContactMail) ? string.Empty : x.ContactMail.Trim(),
							Mobile = string.IsNullOrEmpty(x.ContactMobile) ? string.Empty : x.ContactMobile.Trim(),
							Creator = LoginUser.UserName,
							CreateDate = DateTime.Now,
							CreateIP = LoginUser.IP,
							UserName = LoginUser.UserName,
							OrderNum = orderNum,
							Status = ConstValues.Status.已预订
						};
						DbContext.ProfileTrafficInfo.Add(profileTrafficInfo);
					}

					var mailTraffic = new Traffic()
					{
						TrafficType = x.TrafficType,
						FlightDate = x.FlightDate,
						FlightNum = x.FlightNum,
						TrafficName = trafficMaster.TrafficName,
						Fee = conferenceMaster.IsInternational ? trafficMaster.Price.Value.ToString() + Resources.Dollar :
								trafficMaster.Price.Value.ToString() + Resources.Yuan,
						Sequence = x.Sequence
					};
					mailList.Add(mailTraffic);
				});
				await DbContext.SaveChangesAsync();

				#region SendMail
				var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.MailType == ConstValues.MailType.酒店交通服务邮箱 &&
							x.ConferenceId == model.ConferenceId);

				if (conferenceMailServerMaster == null)
				{
					conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
								x.MailType == ConstValues.MailType.会议邮箱 &&
								x.ConferenceId == model.ConferenceId);
				}

				if (conferenceMailServerMaster != null)
				{
					MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
					MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
					MailAddress to = new MailAddress(model.TrafficList.FirstOrDefault().ContactMail);

					MailMessage message = Utility.GetMailContent(new MailModel
					{
						MailRemark = ConstValues.MailSubject.交通预订,
						Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn,
						ConferenceId = conferenceMaster.ID,
						ConferenceName = conferenceMaster.ConferenceName,
						ConferenceNickName = conferenceMaster.ConferenceNickName,
						Contact = model.TrafficList.FirstOrDefault().ContactName,
						TotalFee = model.TrafficList.FirstOrDefault().TotalFee,
						TrafficList = mailList
					});
					message.To.Add(to);

					if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
					{
						foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
						{
							if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
							{
								message.Bcc.Add(new MailAddress(cc.Trim()));
							}
						}
					}

					var mailTask = Task.Run(() =>
					{
						sender.SendMail(from, message, conferenceMailServerMaster.Password);
					});
				}
				#endregion

				transaction.Commit();
			};

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);

		}

		public async Task<JsonResult> GetHotelTips(string roomId, string checkinDate, string checkoutDate, string roomNumber, string hotelId,
										string currency, string conferenceId, string profileHotelId)
		{
			var roomMaster = await DbContext.RoomMaster.AsNoTracking().FirstOrDefaultAsync(x => x.RoomType == roomId && x.HotelId == hotelId);//这个roomid就是roomType
			var conference = await DbContext.ConferenceMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == conferenceId);
			var roomType = roomMaster.RoomType;
			int number = int.Parse(roomNumber);
			var returnDate = "";
			var errorString = "";
			bool isTrue = true;

			DateTime startDate = conference.CheckinDate.Value;
			DateTime endDate = conference.CheckoutDate.Value;

			DateTime checkin = Convert.ToDateTime(checkinDate);
			DateTime checkout = Convert.ToDateTime(checkoutDate);
			var minLeftRoomCount = DbContext.RoomMaster.AsNoTracking().Where(x => x.HotelId == hotelId && x.RoomType == roomType &&
							x.BookDate.Value >= checkin && x.BookDate.Value < checkout && x.Currency == currency).Min(x => x.LeftRoomCount);

			var model = new HotelCheckinModel
			{
				RoomType = roomType,
				CheckinDateList = new List<string>(),
				CouldBookList = new List<bool>(),
				LeftRoomCount = minLeftRoomCount.HasValue ? minLeftRoomCount.Value : 0
			};

			while (startDate < endDate)
			{
				var room = await DbContext.RoomMaster.AsNoTracking().FirstOrDefaultAsync(x => x.HotelId == hotelId && x.RoomType == roomType &&
							x.BookDate == startDate && x.Currency == currency);
				if (room != null)
				{
					model.CheckinDateList.Add(room.BookDate.Value.ToString("dd"));
					if (Convert.ToDateTime(checkinDate) <= startDate && startDate < Convert.ToDateTime(checkoutDate))
					{
						if (number <= room.LeftRoomCount ||
							DbContext.CheckinInfo.AsNoTracking().Any(x => x.AttendenceId == profileHotelId && x.CheckinDate == startDate))
						{
							model.CouldBookList.Add(true);
						}
						else
						{
							model.CouldBookList.Add(false);
							isTrue = false;
							returnDate = startDate.ToString("yyyy-MM-dd");
							errorString += string.Format(Resources.MsgNotEnoughBookingRoom, returnDate, roomMaster.RoomType) + "<br/>";
						}
						model.LeftRoomCount = (model.LeftRoomCount > room.LeftRoomCount.Value) ? room.LeftRoomCount.Value : model.LeftRoomCount;
						returnDate = (room.LeftRoomCount.Value > number) ? returnDate : startDate.ToString("yyyy-MM-dd");
					}
					else
					{
						model.CouldBookList.Add(false);
					}
				}
				else
				{
					if (Convert.ToDateTime(checkinDate) <= startDate && startDate < Convert.ToDateTime(checkoutDate))
					{
						model.CheckinDateList.Add(startDate.ToString("dd"));
						model.CouldBookList.Add(false);
						model.LeftRoomCount = 0;
						returnDate = startDate.ToString("yyyy-MM-dd");
						errorString += string.Format(Resources.MsgNotEnoughBookingRoom, returnDate, roomMaster.RoomType) + "<br/>";
						isTrue = false;
					}
					else
					{
						model.CheckinDateList.Add(startDate.ToString("dd"));
						model.CouldBookList.Add(false);
					}
				}
				startDate = startDate.AddDays(1);
			}

			if (!isTrue)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(errorString, model), JsonRequestBehavior.AllowGet);
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, model),
						JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonResult> GetCurrency(string conferenceId)
		{
			var sql = DbContext.TrafficMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId &&
						x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key)

					.Union(DbContext.HotelMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.Join(DbContext.RoomMaster.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常),
							hotel => hotel.ID,
							room => room.HotelId,
							(hotel, room) => new
							{
								Currency = room.Currency
							}
						)
						.GroupBy(x => x.Currency).Select(x => x.Key));

			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				currency = x
			});

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		/// <summary>
		/// 获取接机的交通名
		/// </summary>
		/// <returns></returns>
		public async Task<JsonResult> GetReceivingTrafficName(string conferenceId, string currency)
		{
			var result = await DbContext.TrafficMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId &&
						(x.TrafficType == ConstValues.TrafficType.接机 || x.TrafficType == ConstValues.TrafficType.接送机) &&
						x.Currency == currency)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.TrafficName)
					.Select(x => new
					{
						Id = x.ID,
						Name = x.TrafficName,
						Currency = x.Currency,
						Price = x.Price
					})
					.ToListAsync();

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		/// <summary>
		/// 获取送机的交通名
		/// </summary>
		/// <returns></returns>
		public async Task<JsonResult> GetDeliveryTrafficName(string conferenceId, string currency)
		{
			var result = await DbContext.TrafficMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId &&
						(x.TrafficType == ConstValues.TrafficType.送机 || x.TrafficType == ConstValues.TrafficType.接送机) &&
						x.Currency == currency)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.TrafficName)
					.Select(x => new
					{
						Id = x.ID,
						Name = x.TrafficName,
						Currency = x.Currency,
						Price = x.Price
					})
					.ToListAsync();

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}
	}
}